#ifndef _MUNIX_COREMEM_H_
#define _MUNIX_COREMEM_H_
/*******************************************************************************
 ** Name: kmem.h                                                              **
 ** Description: A set of file system definitions for munixOS.                **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2010  Barry Gian James.                                **
 ** All rights reserved.                                                      **
 **                                                                           **
 ** Ref: $HeadURL$
 ******************************************************************************/
// Portions (C) 2011-12 Open Design Strategies, LLC.

// Last Modified $DateTime: 2010/02/12 01:42:30 $ by $Author$
// $URL$
// $Id$
#include <common.h>

#include <boost/shared_ptr.hpp>

#define KMEM_MAX_cache      16

//typedef char * SRAMAddress;
namespace kmem
{

// TODO kmem classes for object caching in the kernel
///////////////////////////////[ event_list
struct event_list
{
	SMART_PTR_DECL(event_list);
};

class object
{
protected:
	SMART_PTR_DECL(object);

    object() { refCnt = 0; event_list = 0; }
    object(const object & kmo) = delete;
    virtual ~object();

    uint8_t       refCnt;     // number of object references to this object
    event_list::pointer event_list; // event list
};

///////////////////////////////[ cache
class cache
{
public:
	SMART_PTR_DECL(cache);
};

typedef void (*ObjFunc)(void *, size_t);

// Wrappers around the KMemslab allocator
void *  kmem_alloc(size_t);
void    kmem_free(void *);

///////////////////////////////[ slab
// A KMemslab is a block of contiguous pages from the VM system that will
// be preallocated in a bunch of KMemobjects.
template <class T>
class slab
{
public:
	SMART_PTR_DECL(slab);

    cache::pointer create(char *,size_t,uint8_t,ObjFunc,ObjFunc);
    void        destroy(cache::pointer &);
    T *         allocate(cache::pointer &, uint8_t);
    void        free(cache::pointer &, T*);

};

// TODO
template<class T>
cache::pointer
slab<T>::create(char * s, size_t s, uint8_t u, ObjFunc f1, ObjFunc f2)
{
	cache	obj = new cache();

	return obj;
}

// TODO
template<class T>
void
slab<T>::destroy(cache::pointer & kmc)
{

}

// TODO
template<class T>
T *
slab<T>::allocate(cache::pointer & kmc, uint8_t am)
{
	T *	newT = new T();

	return newT;
}

// TODO
template<class T>
void
slab<T>::free(cache::pointer & kmc, T* t)
{

}

}	/* namespace kmem */

#endif  /* _MUNIX_COREMEM_H_ */
